package net.cassite.dafstepbystep;

import net.cassite.daf4j.Data;
import net.cassite.daf4j.DataComparable;
import net.cassite.daf4j.DataUtils;
import net.cassite.daf4j.types.XInt;
import net.cassite.daf4j.types.XList;
import net.cassite.daf4j.types.XString;

import javax.persistence.*;
import java.util.List;

/**
 * Created by wkgcass on 15/11/2.
 */
@Entity
public class Privilege {
        public static final int ACCESS_R = 1;
        public static final int ACCESS_U = 2;
        public static final int ACCESS_D = 3;
        public static final int ACCESS_C = 4;

        public final DataComparable<Integer> id = new XInt(this);
        public final Data<String> resource = new XString(this);
        public final DataComparable<Integer> access = new XInt(this);

        public final XList<RP> rps = new XList<RP>(this);

        @OneToMany(mappedBy = "privilege")
        public List<RP> getRps() {
                return rps.get();
        }

        public void setRps(List<RP> rps) {
                DataUtils.set(this.rps, rps);
        }

        @Id
        @GeneratedValue
        public Integer getId() {
                return id.get();
        }

        public void setId(int id) {
                DataUtils.set(this.id, id);
        }

        public String getResource() {
                return resource.get();
        }

        public void setResource(String resource) {
                DataUtils.set(this.resource, resource);
        }

        public int getAccess() {
                return access.get();
        }

        public void setAccess(int access) {
                DataUtils.set(this.access, access);
        }
}
